﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Microsoft.ApplicationBlocks.Data;

namespace DanhMuc
{
    class SucKhoeInfo
    {
        private string _SucKhoeID;

        public string SucKhoeID
        {
            get { return _SucKhoeID; }
            set { _SucKhoeID = value; }
        }

        private string _TenSucKhoe;

        public string TenSucKhoe
        {
            get { return _TenSucKhoe; }
            set { _TenSucKhoe = value; }
        }

        private bool _Active;

        public bool Active
        {
            get { return _Active; }
            set { _Active = value; }
        }
    }

    class SucKhoeCtr
    {
        string strCnn = DBClass_FANIT82.GetConnectString();

        public void Insert(SucKhoeInfo Item)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@SucKhoeID", Item.SucKhoeID),
                new SqlParameter("@TenSucKhoe", Item.TenSucKhoe == null ? (object)DBNull.Value:Item.TenSucKhoe),
                new SqlParameter("@Active", Item.Active == null ? (object)DBNull.Value:Item.Active)
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_SucKhoe_Insert", Para);
        }

        public void Update(SucKhoeInfo Item)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@SucKhoeID", Item.SucKhoeID),
                new SqlParameter("@TenSucKhoe", Item.TenSucKhoe == null ? (object)DBNull.Value:Item.TenSucKhoe),
                new SqlParameter("@Active", Item.Active == null ? (object)DBNull.Value:Item.Active)
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_SucKhoe_Update", Para);
        }

        public void Delete(string strSucKhoeID)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@SucKhoeID", strSucKhoeID),
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_SucKhoe_Delete", Para);
        }

        public DataTable GetList()
        {
            DataSet Ds = SqlHelper.ExecuteDataset(strCnn, CommandType.StoredProcedure, "D_SucKhoe_GetList");
            return Ds.Tables[0];
        }

        public SucKhoeInfo GetByID(string strSucKhoeID)
        {
            SqlDataReader dtr = SqlHelper.ExecuteReader(strCnn, CommandType.StoredProcedure, "D_SucKhoe_Get", new SqlParameter("SucKhoeID", strSucKhoeID));
            SucKhoeInfo ObjSucKhoe = null;
            while (dtr.Read())
            {
                ObjSucKhoe = new SucKhoeInfo();
                ObjSucKhoe.SucKhoeID = dtr["SucKhoeID"].ToString();
                ObjSucKhoe.TenSucKhoe = dtr["TenSucKhoe"].ToString();
                ObjSucKhoe.Active = (bool)dtr["Active"];
            }
            return ObjSucKhoe;
        }
    }
}
